package com.gupao.javavip.rpc.framework.server;

import com.gupao.javavip.rpc.framework.protocol.RPCRequest;
import org.springframework.stereotype.Component;

import java.lang.reflect.Method;

@Component
public class RequestHandler {

    /**
     * 执行远程调用
     *
     * @param request
     * @return
     */
    public Object process(RPCRequest request) {
        try {
            ServiceMapping serviceMapping = RequestHandlerHelper.getServiceMapping(request);
            Object service = serviceMapping.getServiceProvider();
            Method method = serviceMapping.getMethod();
            Object result = method.invoke(service, request.getParams());
            return result;
        } catch (Exception e) {
            e.printStackTrace();
        }

        return null;
    }
}
